package service

import (
	"user_srv/global"
	"user_srv/internal/model/dao"
)

func GetUserIsExists(mobile string) (dao.User, error) {
	var user dao.User
	err := global.DB.Where("mobile = ?", mobile).First(&user).Error
	if err != nil {
		return dao.User{}, err
	}
	return user, err
}

func GetALlCourseInfo() dao.Course {
	var course dao.Course
	err := global.DB.Where("status = ?", 0).First(&course).Error
	if err != nil {
		return course
	}
	return course
}

func GetDelStudyPlan(studyId int) bool {
	var study dao.Study
	err := global.DB.Where("id = ?", studyId).Delete(&study).Error
	if err != nil {
		return false
	}
	return true
}

func GetStudyPlan(studyId int) dao.Study {
	var study dao.Study
	global.DB.Where("id = ?", studyId).First(&study)
	return study
}
func GetCourseInfo(courseId int) dao.Course {
	var course dao.Course
	err := global.DB.Where("id = ?", courseId).First(&course).Error
	if err != nil {
		return course
	}
	return course
}
